package com.vip;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.google.gson.Gson;



public class TestRsp {   
	/** 开发环境**/
	private static String vipShopHttp = "http://oa1.vipshop.com:48991/public_api/gw.php?";
	private static String  api_key = "be3c6d7ac9c1fbbc6fcdb392414a1cc2";
	private static String api_secret = "10971a564eeb3cadfe989e982e66e3f9";
	private static String login_id = "fengchewozai@163.com";  //用户名
    private static String password = "fengchewozai";     //密码
	 
//	/** 測試环境 **/
//	private static String vipShopHttp = "http://216.vipshop.com/public_api/gw.php?";
//	private static String api_key = "04e0dd9c76902b1bfc5c7b3bb4b1db92";
//	private static String api_secret = "90cbc38f8e5d589bf6109219bfa70d0f";
//	private static String login_id = "13430278284";  //用户名
//    private static String password = "123456";     //密码
	
	/** 正式环境 **/
//	private static String vipShopHttp = "http://wi.vipshop.com/public_api/gw.php?";
//	private static String api_key = "04e0dd9c76902b1bfc5c7b3bb4b1db92";
//	private static String api_secret = "90cbc38f8e5d589bf6109219bfa70d0f";
//	private static String login_id = "56654549";  //用户名
//    private static String password = "fengchewozai";     //密码
	
	//private static String vipShopHttp = "http://210.21.83.150:48991/public_api/gw.php?";
	//private static String vipShopHttp = "http://wi.vipshop.com/public_api/gw.php?";
	//vipShopHttp对应账户fengchewozai@163.com   fengchewozai
	//vipShopHttp2 对应账户  fengchewozai@126.com fengcehwozai

	private static String api_sign;  //md5后得到
	private static String fields="";
	private static String format="Json";
    private static String service = "";  //服务名
    private static String user_token = "4a3bcbb4870d4bb7181394d4167dae97";
    public static void main(String[] args) {   
        try {   
        	HttpRequester request = new HttpRequester();
        	User user = new User();
            /**
             * 用户登录
             */
        	//userLogin(request,user); //user_token = d0fc0dbcf3562022ec4c1df5caac129c
        	/**
             * 商品在售
             */
        	//getSelling(request);
        	/**
             * 奢侈品在售
             */
        	//getClubSelling(request);
        	/**
             * 商品预售
             */
        	//getBrandSoon(request);
        	/**
             * 奢侈品预售
             */
        	//getClubBrandSoon(request); //没有数据
        	/**
             * 获取品牌分类
             */
        	//getCategory(request);
        	/**
             * 获取品牌列表
             */
        	//getProducts(request);
        	/**
             * 得到产品详情
             */
        	//getProduct(request);
        	/**
             * 获取商品尺寸
             */
        	//getProductSku(request);
        	/**
             * 分类接口 返回
             */
        	//getChannel(request);
        	/**
             * 根据id返回分类商品
             */
        	//getChannelId(request);
        	/**
             * 添加商品到购物袋
             */
        	//addCar(request,user);
        	/**
             * 删除购物车
             */
        	//deleteCar(request);
        	/**
             * 购物车
             */
            //getCar(request,user);
        	
        	/**
             * 清除购物车
             */
        	//clearCar(request);
        	/**
             * 提交订单
             */
        	//orderSubmit(request,user);
        	/**
             * 获取支付方式
             */
        	//getPayMents(request);
        	/**
             * 获取用户订单列表
             */
        	//getOrders(request);
        	/**
             * 获取用户订单详情
             */
        	//getOrder(request);
        	/**
             * 取消用户订单
             */
        	//orderCancel(request);
        	/**
             * 用户历史订单列表
             */
        	//getHistoryOrders(request);

        	/**
             * 注册用户
             */
        	//userBaseAdd(request);
        	/**
             * 添加用户地址
             */
        	//addUserAddress(request);
        	/**
             * 删除用户地址
             */
        	//addressesDelete(request);
        	/**
             * 获取用户地址
             */
        	getAddresses(request);
        	/**
             * 更新用户地址
             */
        	//addressUpadte(request);
        	/**
             * 邮政编码查询
             */
        	//getZipcode(request);
        	/**
             * 省市区查询
             */
        	//getArea(request);
        	/**
             * 激活代金券
             */
        	//addFavourables(request);
        	/**
             * 代金卷列表
             */
        	//getFavourables(request);
        } catch (Exception e) {   
            e.printStackTrace();   
        }   
    }   
    /**
     * 品牌预售
     * @param request
     */
    private static void getBrandSoon(HttpRequester request){
    	String fields = "brand_name,index_image,logo,sell_time_from,sell_time_to";
    	String dictionary = api_key+fields+"json"+"vipshop.brand.soon.get"+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp +
		"api_key="+api_key+"&" +
		"api_sign="+api_sign+"&" +
		"fields="+fields+
		"&format=json&" +
		"service=vipshop.brand.soon.get";

		System.out.println(test);
		String jsonRsp = request.sendDataPost(test, null);
		System.out.println("rsp getBrandSoon:" + jsonRsp);
    }
    /**
     * 奢侈品牌预售
     * @param request
     */
    private static void getClubBrandSoon(HttpRequester request){
    	
    	String service = "vipclub.brand.soon.get";
    	String fields = "brand_name,index_image,logo,sell_time_from,sell_time_to";
    	String dictionary = api_key+fields+"json"+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp +
		"api_key="+api_key+"&" +
		"api_sign="+api_sign+"&" +
		"fields="+fields+
		"&format=json&" +
		"service="+service;

		System.out.println(test);
		String jsonRsp = request.sendDataPost(test, null);
		System.out.println("rsp getBrandSoon:" + jsonRsp);
    }
    /**
     * 用户登陆
     * @param request
     */
    private static void userLogin(HttpRequester request,User user){
    	password = MD5.getMD5(password.getBytes());//md5一次 登陆密码
    	service ="vipshop.user.base.login";
    	String format = "json";
    	String fields = "user_token";
    	String dictionary = api_key+fields+format+login_id+password+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	//构造用户登陆地址
    	String http = vipShopHttp+
    	"api_key="+api_key+
    	"&api_sign="+api_sign+
    	"&fields="+fields+
    	"&format="+format+
    	"&login_id="+login_id+
    	"&password="+password+
    	"&service="+service;
    	
    	System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userLogin:"+jsonRsp);
    	//List<User> userList = request.getUserGsonList(jsonRsp);
    	Gson gson = new Gson();
    	 User user2 = gson.fromJson(jsonRsp.toString(), User.class);
    	 user.setUser_token(user2.user_token) ;
    	System.out.println(user2.user_token);
    }
    /**
     * 在售普通名牌商品
     */
    private static void getSelling(HttpRequester request){
    	service = "vipshop.brand.selling.get";
    	format = "xml";
    	fields = "brand_id,brand_name,index_image,logo,sell_time_from,sell_time_to,agio";
    	String dictionary = api_key+fields+format+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String http = vipShopHttp+
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    	"fields="+fields+
    	"&format="+format+
    	"&service="+service;
    	System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp getSelling:"+jsonRsp);
//    	List<SellingBean> sellingList = request.getGsonList(jsonRsp);
//    	for (SellingBean sellingBean : sellingList) {
//			System.out.println(getLongTime2Date(sellingBean.sell_time_from));
//		}
    	
    }
    /**
     * 在售奢侈品牌商品
     */
    private static void getClubSelling(HttpRequester request){
    	service = "vipclub.brand.selling.get";
    	format = "json";
    	fields = "brand_id,brand_name,index_image,logo," +
    			"sell_time_from,sell_time_to,seo_title,seo_keyword," +
    			"seo_description,period,agio";
    	String dictionary = api_key+fields+format+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String http = vipShopHttp+
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    	"fields="+fields+"&format="+format+"&service="+service;
    	System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp getSelling:"+jsonRsp);
    }
    /**
     * 获取品牌分类
     * @param request
     */
    private static void getCategory(HttpRequester request){
    	String service="vipshop.brand.category.get";
    	String format = "json";
    	String fields = "cat_id,cat_name";
    	String brand_id="";
    	String dictionary = api_key+brand_id+fields+format+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    	"brand_id="+brand_id+
		"&fields=cat_id,cat_name&"+
		"format="+format+
		"&service="+service;
		System.out.println(test);
		String jsonRsp = request.sendDataPost(test, null);
		System.out.println("rsp addCar:" + jsonRsp);
    }
    /**
     * 得到产品详情
     * @param request
     */
    private static void getProduct(HttpRequester request ){
    	service = "vipshop.brand.product.get";
    	int product_id = 128525 ;
    	String fileds = "product_id,brand_id,product_name,vipshop_price,market_price,agio,small_image,sale_out," +
    	"standard,wash,color,material,descript,cat_id,img_pre,size_table_html";
    	String dictionary = api_key+fileds+"xml"+product_id+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	
    	String http =  vipShopHttp+
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign
    	+"&fields="+fileds
    	+"&format="+"xml"
    	+"&product_id="+product_id
    	+"&service="+service;
    	
    	System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp getProduct:"+jsonRsp);
    	//List<Object> jsonList = parseFromJson(jsonRsp);
    }
    /**
     * 获取商品尺寸
     * @param request
     */
    private static void getProductSku(HttpRequester request){
    	service = "vipshop.product.sku.get";
    	String fields = "sku_id,sku_name";
    	int product_id = 746760;
    	String dictionary = api_key+fields+"json"+product_id+service+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
		"fields="+fields+
		"&format=json&" +
		"product_id="+product_id+
		"&service="+service;
		System.out.println(test);
		String jsonRsp = request.sendDataPost(test, null);
		System.out.println("rsp getProductSku:" + jsonRsp);
    }
    /**
     * 添加商品到购物车
     * @param request
     */
    private static void addCar(HttpRequester request,User user){
    	service = "vipshop.shop.cart.add";
    	int sku_id = 2052110;
    	//String num = "1";
    	
    	String dictionary = api_key+"json"+"1"+"vipshop.shop.cart.add"+sku_id+user_token+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp+
    	"api_key="+api_key+
		"&api_sign="+api_sign+
		"&format=json" +
		"&num=1" +
		"&service=vipshop.shop.cart.add" +
		"&sku_id="+sku_id+
		"&user_token="+user_token;
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp addCar:"+jsonRsp);
    }
    /**
     * 删除购物车商品
     * @param request
     */
    private static void deleteCar(HttpRequester request){
    	service = "vipshop.shop.cart.delete";
    	String format = "json";
    	String cart_id ="3845";
    	String dictionary = api_key+cart_id+format+service+"9a3038032197eb526662364838333413"+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp +
    	        "api_key="+api_key+"&" +
    			"api_sign="+api_sign+"&" +
    			"cart_id="+cart_id+
    			"&format=json&" +
    			"service=" +service+
    			"&user_token=9a3038032197eb526662364838333413"; 
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp deleteCar:"+jsonRsp);
    }
    /**
     * 查询购物车
     * @param request
     */
    private static void getCar(HttpRequester request,User user){
    	String fields = "cart_id,product_id,product_name,small_image";
    	String format = "xml";
    	String dictionary = api_key+fields+format+"vipshop.shop.cart.get"+user_token+api_secret;
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp 
    	        +"&api_key="+api_key
    			+"&api_sign="+api_sign 
    			+"&fields="+fields
    			+"&format=" +format
    			+"&service=vipshop.shop.cart.get" 
    			+"&user_token="+user_token; 
    	System.out.println("api_sign:"+api_sign);
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getCar:"+jsonRsp);
    }
    
    /**
     * 清空购物袋
     * @param request
     */
    private static void clearCar(HttpRequester request){
    	String dictionary = "api_key1jsonvipshop.shop.cart.clear"
    	+"9d8f050861240153d04ce3c54d3099fb";
    	String api_sign = MD5.getMD5(dictionary.getBytes());
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    			"api_sign="+api_sign+"&" +
    			"format=json&" +
    			"service=vipshop.shop.cart.clear&" +
    			"user_token=9d8f050861240153d04ce3c54d3099fb"; 
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp addCar:"+jsonRsp);
    }
    /**
     * 激活代金券
     * @param request
     */
    private static void addFavourables(HttpRequester request ){
    	service = "vipshop.user.favourable.add";
    	String format = "xml";
    	String fields = "product_id,product_name";
    	String api_sign = api_key+"1065"+fields+format+"1"+"10000"+service+api_secret;
    	api_sign = getApi_sign(api_sign);
   	String http =  vipShopHttp+
   	"api_key="+api_key+"&" +
    	"favourable_code=115111073139002166&"+
    	"format=json&"+
    	"service=vipshop.user.favourable.add&"+
    	"user_token=4569aa9249b57ffd1e28f9809553931d";
    	System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp getFavourables:"+jsonRsp);
    	//List<Object> jsonList = parseFromJson(jsonRsp);
    }
    /**
     * 代金卷列表
     * @param request
     */
    private static void getFavourables(HttpRequester request ){
    	service = "vipshop.user.favourables.get";
    	String format = "json";
    	String api_sign = api_key+format+service+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String http =  vipShopHttp+
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    	"format=json&"+
    	"service="+service+
    	"&user_token="+user_token;
    	System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp getFavourables:"+jsonRsp);
    	//List<Object> jsonList = parseFromJson(jsonRsp);
    }
    /**
     * 用户注册
     */
    private static void userBaseAdd(HttpRequester request){
    	//计算api_sign
    	String password = MD5.getMD5("123456".getBytes());//md5一次 登陆密码
    	String api_sign = api_key+"19870201"+"user_token"+"json"+"0"+"invite@vipshop.com"+"13430278284"+"phone"+password+"vipshop.user.base.add"+"demo"
    	+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test  = vipShopHttp +
    	        "api_key="+api_key+
    	        "&api_sign="+api_sign+
    	        "&birthday=19870201" +
    	        "&fields=user_token" +
    			"&format=json" +
    			"&gender=0" +
    			"&invite=invite@vipshop.com" +
    			"&login_id=13430278284" +
    			"&login_type=phone" +
    			"&password="+password+
    			"&service=vipshop.user.base.add" +
    			"&use_name=demo";
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp userBaseAdd:"+jsonRsp);
    }
    /**
     *  获取商品列表
     * @param request
     */
    private static void getProducts(HttpRequester request){
    	service = "vipshop.brand.products.get";
    	String format = "xml";
    	String fields = "product_id,product_name";
    	String api_sign = api_key+"4916"+fields+format+"1"+"10000"+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    			String test = vipShopHttp
    			+"api_key="+api_key 
    			+"&api_sign="+api_sign
    			+"&brand_id=4916"
    			+"&cat_id=" 
    			+"&fields="+fields 
    			+"&format=" +format
    			+"&page=1"
    			+"&page_size=10000"
    			+"&service="+service;
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getProducts:"+jsonRsp);
    }
    
    /**
     * 添加用户地址
     * @param request
     */
    private static void addUserAddress(HttpRequester request ){
    	//计算api_sign
    	service = "vipshop.user.addresses.add";
    	String format = "json";
    	String fields = "address_id";//392
    	String api_sign = "广州天河北路898号"+api_key+"101011"+"sdfasdfsd"+fields+format+"15012852360"+"518053"+service+"075512345698"+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	getApi_sign(api_sign);
    	String test = vipShopHttp +
    			"address=广州天河北路898号&" +
    			"api_key="+api_key+"&" +
    			"api_sign="+api_sign+"&" +
    			"area_id=101011&" +
    			"consignee=sdfasdfsd&" +
    			"fields=" +fields+
    			"&format=json&" +
    			"mobile=15012852360&" +
    			"postcode=518053&" +
    			"service="+service +
    			"&tel=075512345698&" +
    			"user_token="+user_token;
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp addUserAddress:"+jsonRsp);
    }
    /**
     * 删除用户地址
     * @param request
     */
    private static void addressesDelete(HttpRequester request){
    	//计算api_sign
    	service = "vipshop.user.addresses.delete";
    	String format = "json";
    	api_sign = getApi_sign(api_sign);
    	String api_sign = "391"+api_key+format+service+user_token+api_secret;
    	getApi_sign(api_sign);
    	String test = vipShopHttp +
		"address_id=391&" +
		"api_key="+api_key+"&" +
		"api_sign="+api_sign+"&" +
		"&format=json&" +
		"service="+service +
		"user_token="+user_token;
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp addUserAddress:"+jsonRsp);
    }
    /**
     * 修改用户地址
     * @param request
     */
    private static void addressUpadte(HttpRequester request){
    	//计算api_sign
    	service = "vipshop.user.addresses.update";
    	String format = "json";
    	String api_sign = "广州天河北路898号"+"391"+api_key+"101012"+"sdfasdfsd"+format+"15012852360"+"518053"+service+"075512345698"+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	getApi_sign(api_sign);
    	String test = vipShopHttp +
    			"address=广州天河北路898号&" +
    			"address_id=391&" +
    			"api_key="+api_key+"&" +
    			"api_sign="+api_sign+"&" +
    			"area_id=101012&" +
    			"consignee=sdfasdfsd&" +
    			"&format=json&" +
    			"mobile=15012852360&" +
    			"postcode=518053&" +
    			"service="+service +
    			"&tel=075512345698&" +
    			"user_token="+user_token;
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp addressUpadte:"+jsonRsp);
    }
    /**
     * 获取用户地址
     * @param request
     */
      private static void getAddresses(HttpRequester request){
    	  service = "vipshop.user.addresses.get";
      	String format = "json";
      	String api_sign = api_key+format+service+user_token+api_secret;
      	api_sign = getApi_sign(api_sign);
    	String test =vipShopHttp +
    	       "api_key="+api_key+"&" +
    	       "api_sign="+api_sign+"&" +
    			"format=json&" +
    			"service="+service +
    			"&user_token="+user_token;
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp addressesDelete:"+jsonRsp);
     }
    /**
     * 提交订单
     * @param request
     */
    private static void orderSubmit(HttpRequester request,User user){
    	service = "vipshop.shop.order.submit";
    	String format = "json";
    	String fields = "order_sn";
    	String api_sign = "469"+api_key+fields+format+"8"+service+"3"+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    			"address_id=469&" +
    			"api_key="+api_key+"&" +
    			"api_sign="+api_sign+"&" +
    			//"favourable_id=577&" +
    			"fields="+ fields+
    			"&format=json&" +
    			"invoice=&" +
    			"pay_type=8&"+
    			"service="+service +
    			"&transport_day=3&" +
    			"user_token="+user_token;
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp orderSubmit:"+jsonRsp);
    }
    /**
     * 获取用户订单列表
     * @param request
     */
    private static void getOrders(HttpRequester request){
    	service = "vipshop.user.orders.get";
    	String format = "json";
    	String fields = "order_sn,order_type,order_type_name,order_status,order_status_name";
    	String api_sign = api_key+fields+format+service+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" + 
    	"api_sign="+api_sign+"&" +
    			"fields="+fields +
    			"&format=json&" +
    			"service="+service +
    			"&user_token="+user_token;
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getOrders:"+jsonRsp);
    }
    /**
     * 获取用户订单详情
     * @param request
     */
    private static void getOrder(HttpRequester request){
    	service = "vipshop.user.order.get";
    	String format = "xml";
    	String order_sn = "";
    	String api_sign = api_key+format+order_sn+service+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    			//"fields=order_sn,product_id,product_name,num,brand_name&" +
    			"format=json&" +
    			"order_sn="+order_sn +
    			"&service=" +service+
    			"&user_token="+user_token;
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp orderSubmit:"+jsonRsp);
    }
    /**
     * 用户历史订单列表
     * @param request
     */
    private static void getHistoryOrders(HttpRequester request){
    	service = "vipshop.user.favourable.add";
    	String format = "xml";
    	String fields = "product_id,product_name";
    	String api_sign = api_key+"1065"+fields+format+"1"+"10000"+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    			//"fields=order_sn,order_type,order_type_name,order_status,order_status_name&" +
    			"format=json&" +
    			"service=vipshop.user.historyorders.get&" +
    			"user_token=4569aa9249b57ffd1e28f9809553931d";
    	
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getHistoryOrders:"+jsonRsp);
    }
    /**
     * 取消用户订单
     * @param request
     */
    private static void orderCancel(HttpRequester request){
    	service = "vipshop.user.order.cancel";
    	String format = "json";
    	String fields = "code,msg";
    	String order_sn = "";
    	String api_sign = api_key+fields+format+order_sn+service+user_token+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    			"fields=="+fields +
    			"&format=json&" +
    			"order_sn="+order_sn +
    			"&service=vipshop.user.order.cancel&" +
    			"user_token="+user_token;
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp orderSubmit:"+jsonRsp);
    }
    /**
     * 获取支付方式
     * @param request
     */
    private static void getPayMents(HttpRequester request){
    	service = "vipshop.shop.payments.get";
    	String format = "json";
    	String fields = "paytype_id,paytype_name,min_money,max_money,type,platform";
    	String api_sign = api_key+fields+format+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
		"fields="+fields +
		"&format=json&" +
		"service="+service;
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getPayMents:"+jsonRsp);
    }
    
    /**
     * 邮政编码查询
     * @param request
     */
    private static void getZipcode(HttpRequester request){
    	service = "vipshop.user.favourable.add";
    	String format = "xml";
    	String fields = "product_id,product_name";
    	String api_sign = api_key+"1065"+fields+format+"1"+"10000"+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"area_id=100000&"+
		"fields=zipcode&" +
		"format=json&" +
		"service=vipshop.shop.zipcode.get";
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getZipcode:"+jsonRsp);
    }
    
    /**
     * @param request
     * 省市区查询
     */
    private static void getArea(HttpRequester request){
    	service = "vipshop.user.favourable.add";
    	String format = "xml";
    	String fields = "product_id,product_name";
    	String api_sign = api_key+"1065"+fields+format+"1"+"10000"+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"city=json&" +
    	"district=json&" +
		"fields=province_id,province_name,city_id,city_name,district_id,district_name&" +
		"format=json&" +
		"province=广东省&"+
		"service=vipshop.shop.area.get";
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getZipcode:"+jsonRsp);
    }
    
    /**
     * 分类接口 返回 (男士,女士,儿童,生活,奢侈品)
     * @param request
     */
    private static void getChannel(HttpRequester request){
    	service = "vipshop.brand.channel.get";
    	String format = "xml";
    	String api_sign = api_key+format+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
		"format=xml&" +
		"service=vipshop.brand.channel.get";
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getZipcode:"+jsonRsp);
    }
    /**
     * 根据id返回分类商品 (男士,女士,儿童,生活,奢侈品)
     * @param request
     */
    private static void getChannelId(HttpRequester request){
    	service = "vipshop.brand.selling.get";
    	String format = "xml";
    	String channel_id = "2";
    	String api_sign = api_key+channel_id+format+service+api_secret;
    	api_sign = getApi_sign(api_sign);
    	String test = vipShopHttp +
    	"api_key="+api_key+"&" +
    	"api_sign="+api_sign+"&" +
    	"channel_id="+channel_id+
		"&format=xml" +
		"&service=vipshop.brand.selling.get";
    	System.out.println(test);
    	String jsonRsp = request.sendDataPost(test, null);
    	System.out.println("rsp getChannelId:"+jsonRsp);
    }
    //public_api/gw.php?service=vipshop.brand.selling.get&channel_id=1
    /**
     * 计算 api_sign
     */
    private static String getApi_sign(String api_sign){
    	api_sign = MD5.getMD5(api_sign.getBytes());
    	return api_sign;
    }
    /**
	 * 将时间戳转成日期字符
	 * @param longtime
	 * @return
	 */
	public static String getLongTime2Date(String longtime)
	{  
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Long timestamp = Long.parseLong(longtime)*1000;  
		return sdf.format(new Date(timestamp));  
	}

} 
